from PyQt4.QtGui import QDialog, QListWidgetItem
from ui_chooser import Ui_chooser

from common.terrain import Terrain
from mapeditor.core.memanager import MEManager

class Chooser(QDialog, Ui_chooser):
	"""
	CGCraft MapEditor's chooser dialog.
	"""
	
	def __init__(self, items, parent=None):
		"""
		Constructor.
		"""
		
		super(Chooser, self).__init__(parent)
		self.setupUi(self)
		self.btnOk.setDefault(True)
		
		for i in items:
			self.list.addItem(QListWidgetItem(i))
			
		if len(items) > 0:
			self.list.setCurrentRow(0)
			self.selection = items[0]
		else:
			self.selection = None

	def itemChanged(self):
		"""
		Event called when an item is selected.
		"""
		
		if len(self.list.selectedItems()) == 0: return
		self.selection = self.list.selectedItems()[0].text()
	